package com.test.controller;

import com.test.annotation.OperateLog;
import com.test.service.IHelloService;
import com.test.utils.AnnotationUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.lang.annotation.Annotation;

/**
 * @Classname： LogController
 * @Description：
 * @Author： xiedong
 * @Date： 2019/11/11 18:07
 * @Version： 1.0
 **/
@RestController
@Slf4j
public class LogController {
    @Autowired
    private IHelloService helloService;

    @RequestMapping("/test")
    @OperateLog(system = "系统1",flag = 1,operatorName = "操作员1")
    public void test() throws Exception {
        OperateLog test = (OperateLog)AnnotationUtil.getAnnotation(LogController.class, OperateLog.class, "test", 1);
        log.info("更改前的注解属性:【{}】,【{}】,【{}】",test.flag(),test.operatorName(),test.system() );
        //更改注解OperateLog的system属性值为“系统2”
        AnnotationUtil.ModifyAnnotation(LogController.class, OperateLog.class, "test", "system", "系统2");
        //更改flag的属性值为2
        AnnotationUtil.ModifyAnnotation(LogController.class, OperateLog.class, "test", "flag", 2);
        //更改注解的operatorName属性值为：张三
        AnnotationUtil.ModifyAnnotation(LogController.class, OperateLog.class, "test", "operatorName", "张三");
        log.info("更改后的注解属性:【{}】,【{}】,【{}】",test.flag(),test.operatorName(),test.system() );
    }
    @RequestMapping("/test1")
    @OperateLog(system = "系统1",flag = 1,operatorName = "操作员1")
    public void test1() throws Exception {
        helloService.IsayHello();
    }
    @RequestMapping("/test2")
    @OperateLog(system = "系统1",flag = 1,operatorName = "操作员1")
    public void test2() throws Exception {
        helloService.say("我是controller");
    }
    @RequestMapping("/test3")
    @OperateLog(system = "系统1",flag = 1,operatorName = "操作员1")
    public void test3() throws Exception {
        helloService.error(true);
    }
    @RequestMapping("/test4")
    @OperateLog(system = "系统1",flag = 1,operatorName = "操作员1")
    public void test4() throws Exception {
        helloService.error(false);
    }
}
